let request = require('../../utils/request.js')
Page({
    data:{
        lists: [],
        total: 1,
        height: '',
        pagenumber: 1,
        refund: {}
    },
    enter (e) {
      my.navigateTo({
          url:'detail?detail='+JSON.stringify(e.currentTarget.dataset.detail)
      })
    },
    getData (){
      if (this.data.pagenumber<=this.data.total) {
        let success=(data)=>{
          if (this.data.pagenumber>parseInt(data["pagesum"])) {
            this.data.lists=[]
          } else {
            let list = data["res"]
            // for(let i=0;i<list.length;i++){
            //   list[i].num = list[i].num.slice(0,20)
            // }
            // this.data.lists = this.data.lists.concat(data["res"])
            this.data.lists = this.data.lists.concat(list)
          }
          this.setData({
            lists:this.data.lists
          })
          this.data.total=parseInt(data["pagesum"]);
          this.data.pagenumber++;
        }
        request.postdata('/Order',{"pagination":this.data.pagenumber},success,this)
      }
    },
    onShow () {
      my.getNetworkType({
        success: (res) => {
          if(!res.networkAvailable||res.networkType=='UNKNOWN'){
            my.showToast({
              content: '网络状态不佳，请检查网络',
              type:'fail',
              duration: 2000
            })
          }
        }
      })
      my.getSystemInfo({
        success: (res)=> {
          this.setData({
            height:res.windowHeight+'px'
          })
        }
      })
      this.setData({
        pagenumber: 1,
        lists: [],
        total: 1,
        showd: false
      });
     this.getData()
    },
    refresh (e){
      this.data.pagenumber=1
      this.data.total=1
      this.data.lists=[]
      this.getData()
    },
    more (e){
      this.getData()
    },
    tochangestatus(e){
      my.navigateTo({
        url: '/pages/home/state?num=' + e.currentTarget.dataset.detail.num
      });
    },
    refund(e){
      this.data.refund.num = e.currentTarget.dataset.detail.num
      this.data.refund.money = e.currentTarget.dataset.detail.money
      let success=(data)=>{
        this.getData()
      }
      request.postdata('/aliRefund', this.data.refund, success, this)
    },
})